package com.jyxd.web.service.patient;

import com.jyxd.web.dao.patient.PatientCriticalDescriptionDao;
import com.jyxd.web.data.dto.HttpResult;
import com.jyxd.web.data.patient.PatientCriticalDescription;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;
import java.util.Objects;

import static com.jyxd.web.util.ExecuteUtil.errorIfEmpty;

@Service
public class PatientCriticalDescriptionService {

    @Autowired
    private PatientCriticalDescriptionDao patientCriticalDescriptionDao;

    public boolean insert(PatientCriticalDescription patientCriticalDescription) {
        return patientCriticalDescriptionDao.insert(patientCriticalDescription);
    }

    public boolean update(PatientCriticalDescription patientCriticalDescription) {
        return patientCriticalDescriptionDao.update(patientCriticalDescription);
    }

    public PatientCriticalDescription queryDateByPatientIdAndCriticalDescription(Map<String, Object> map) {
        return patientCriticalDescriptionDao.queryDateByPatientIdAndCriticalDescription(map);
    }

    /**
     * 查询新的危急值
     *
     * @return
     */
    public HttpResult getNewCriticalDescription(Map<String, Object> map) {
        errorIfEmpty(map, "参数不能为空");
        errorIfEmpty(map.get("patientId"), "查询患者id不能为空");
        PatientCriticalDescription patientCriticalDescription = queryDateByPatientIdAndCriticalDescription(map);
        return Objects.isNull(patientCriticalDescription) ?
                new HttpResult(200, "暂无数据") :
                new HttpResult(200, patientCriticalDescription, "查询数据成功");
    }
}
